package pers.cz.admin;

import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.util.unit.DataSize;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
import pers.cz.spring.SpringContextUtil;

import javax.servlet.MultipartConfigElement;

/**
 * 启动类
 * @program: PostGirl-panent
 * @description: PostGirlApplication
 * @author: Cheng Zhi
 * @create: 2021-02-27 23:16
 **/
@SpringBootApplication(scanBasePackages="pers.cz.*",exclude = {DataSourceAutoConfiguration.class})
@MapperScan(basePackages="pers.cz.mapper")
@EnableCaching
public class PostGirlApplication {
    public static void main(String[] args) {
        Logger logger= LoggerFactory.getLogger(PostGirlApplication.class);
        // SpringApplication.run(PostGirlApplication.class, args);
        ApplicationContext ctx = SpringApplication.run(PostGirlApplication.class, args);
        logger.info("=======================================");
        logger.info("==     ~~~   启动成功    ~~~         ==");
        logger.info("=======================================");

        // -------start----这里打印一下所有的被注入到容器的bean对象
 /*       for (String beanName : SpringContextUtil.getBeanNames()) {
            System.out.println("--------bean object------" + beanName);
        }*/
/*        String[] beans = ctx.getBeanDefinitionNames();
        Arrays.sort(beans);
        for (String bean : beans) {
            System.out.println(bean + " of Type :: " + ctx.getBean(bean).getClass());
        }*/

    }


    /**
     * 文件上传配置Parameter
     * @return
     */
    @Bean
    public MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        //单个文件最大
        factory.setMaxFileSize(DataSize.parse("10240KB")); //KB,MB
        /// 设置总上传数据总大小
        factory.setMaxRequestSize(DataSize.parse("102400KB"));
        return factory.createMultipartConfig();
    }

    /**
     * 创建websocket实例
     * @return
     */
    @Bean
    public ServerEndpointExporter serverEndpointExporter() {
        return new ServerEndpointExporter();
    }
}
